package com.readmark;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.add.Job1;
import com.add.Job2;
import com.add.Post;
import com.get.Job1Impl;
import com.get.Job2Impl;
import com.get.PostImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class ReadMoreServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		HttpSession session = request.getSession();
		JSONObject message=new JSONObject();
		if(session.getAttribute("uId")!=null){
			int jobid=Integer.valueOf(String.valueOf(session.getAttribute("jobid")));
			String paytype=String.valueOf(session.getAttribute("paytype"));
			System.out.println(jobid+".........."+paytype);
			Post post=null;
			PostImpl pi=new PostImpl();
			if(paytype.equals("日结")){
				Job1Impl ji1=new Job1Impl();
				Job1 j1=ji1.getJob1(jobid);
				post=pi.getPost(j1.getPostId());
				message.put("joboffer", post.getPlace());
				message.put("postdate", post.getDate());
				message.put("jobid", j1.getId());
				message.put("jobname", j1.getJobName());
				message.put("paytype", j1.getPayType());
				message.put("jobplace", j1.getPlace());
				message.put("salary", j1.getSalary());
				message.put("notice", j1.getNotice());
				message.put("date", j1.getWorkTime());
			}
			else{
				Job2Impl ji2=new Job2Impl();
				Job2 j2=ji2.getJob1(jobid);
				post=pi.getPost(j2.getPostId());

				message.put("joboffer", post.getPlace());
				message.put("postdate", post.getDate());
				message.put("jobid", j2.getId());
				message.put("jobname", j2.getJobName());
				message.put("paytype", j2.getPayType());
				message.put("jobplace", j2.getPlace());
				message.put("salary", j2.getSalary());
				message.put("notice", j2.getNotice());
				message.put("date", j2.getDate());
				message.put("time1", j2.getTime1());
				message.put("time2", j2.getTime2());
				message.put("time3", j2.getTime3());
			}
		}
		else{

			message.put("message", "无");
			
		}
		response.getWriter().print(message);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
